package garin.parse.sql.sql2003;

import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class ResourceManager {
	private static void close(final Closeable c) throws IOException {
		if (c == null) return;
		c.close();
	}
	
	private static String doGet(final String fileName) throws IOException {
		InputStream in = null;
		InputStreamReader inr = null;
		BufferedReader bin = null;
		try {
			in = ResourceManager.class.getResourceAsStream(fileName);
			inr = new InputStreamReader(in);
			bin = new BufferedReader(inr);
			final StringBuilder sb = new StringBuilder();
			String line;
			while (null != (line = bin.readLine())) {
				sb.append(line);
				sb.append("\n");
			}
			return sb.toString();
		} finally {
			close(bin);
			close(inr);
			close(in);
		}
	}
	
	public static String get(final String resourceFile) {
		try {
			return doGet(resourceFile);
		} catch (final IOException e) {
			throw new RuntimeException(e);
		}
	}
}
